package cn.wolfcode.web.interceptor;

import cn.wolfcode.domain.Employee;

import cn.wolfcode.util.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CheckloginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //获取当前登录的用户

       // Object employee = request.getSession().getAttribute("EMPLOYEE_IN_SESSION");
        Employee employee = UserContext.getCurrentUser();
        if (employee == null) { //没有登录,不放行
            response.sendRedirect("/login.html"); //回到登录界面
            return false;
        }
        return true; //已经登录,放行
    }
}